package com.wll.android.drawp1;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class Practice6DrawLineView extends View {
    Paint paint = new Paint();

    public Practice6DrawLineView(Context context) {
        super(context);
    }

    public Practice6DrawLineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice6DrawLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawLine() 方法画直线
        paint.setStrokeWidth(10);
        canvas.drawLine(120, 300, 460, 500, paint);

        float[] pts = {
                640, 320, 840, 320,
                740, 320, 740, 480,
                600, 480, 880, 480
        };
        paint.setStrokeWidth(10);
        canvas.drawLines(pts, paint);

        float[] pts2 = {
                640, 620, 840, 620,
                740, 620, 740, 780,
                600, 780, 880, 780
        };
        paint.setStrokeWidth(20);
        canvas.drawLines(pts2,4,8,paint);
    }
}
